﻿using System;
using UnityEngine;


/// <summary>
/// 
/// </summary>
public class KeyCodeListener : MonoBehaviour
{
    public bool isKeyPressed = false;

    public event Action OnStateChanged;

    public KeyCode keyCode  = KeyCode.Escape;


    void Update()
    {
        if (Input.GetKeyDown(keyCode))
        {
            isKeyPressed = true;
        }

        if (Input.GetKeyUp(keyCode) && isKeyPressed)
        {
            isKeyPressed = false;

            OnStateChanged?.Invoke();
        }
    }
}